Collecting Info on A Specific Teams Games Over a Specific Period

This vignette shows you how to collect gameids for a specific team during a specific time and aggregate corresponding box score information.

Specifically, it will walk you through collecting information on all Phoenix Suns games that took place during December and January of the 2006-07 season.


In [1]:
import goldsberry
import pandas as pd
pd.set_option("display.max_columns",50) # Change Pandas Display Options
goldsberry.__version__


Out[1]:
'1.0.1'

In [2]:
gameids = goldsberry.GameIDs()
gameids2015 = pd.DataFrame(gameids.game_list())
gameids2015.head()


Out[2]:
AST BLK DREB FG3A FG3M FG3_PCT FGA FGM FG_PCT FTA FTM FT_PCT GAME_DATE GAME_ID MATCHUP MIN OREB PF PLUS_MINUS PTS REB SEASON_ID STL TEAM_ABBREVIATION TEAM_ID TEAM_NAME TOV VIDEO_AVAILABLE WL
0 41 8 38 28 13 0.464 86 56 0.651 23 19 0.826 2016-04-13 0021501226 MIN vs. NOP 240 5 20 35 144 43 22015 14 MIN 1610612750 Minnesota Timberwolves 13 1 W
1 40 5 30 27 14 0.519 91 56 0.615 19 13 0.684 2016-03-29 0021501108 ORL vs. BKN 240 5 29 34 139 35 22015 11 ORL 1610612753 Orlando Magic 10 1 W
2 28 4 45 29 8 0.276 124 56 0.452 46 27 0.587 2015-12-18 0021500391 DET @ CHI 340 19 35 3 147 64 22015 7 DET 1610612765 Detroit Pistons 11 1 W
3 35 4 34 25 13 0.520 88 53 0.602 16 11 0.688 2016-02-25 0021500855 GSW @ ORL 240 8 21 16 130 42 22015 9 GSW 1610612744 Golden State Warriors 21 1 W
4 30 2 36 23 9 0.391 87 53 0.609 34 27 0.794 2016-01-02 0021500496 SAC vs. PHX 240 10 23 23 142 46 22015 9 SAC 1610612758 Sacramento Kings 15 1 W

Like the PlayerList() class, the GameIDs() class defaults to the current season. If we want the 2006-07 season, we need to identify and change the proper parameters. We can see the available parameters to set by printing the api_params attribute.


In [3]:
gameids.api_params


Out[3]:
{'Direction': 'DESC',
 'LeagueID': '00',
 'PlayerOrTeam': 'T',
 'Season': '2015-16',
 'SeasonType': 'Regular Season',
 'Sorter': 'FGM'}

From there, we can see we should set the Season value to 2006-07. Once we set the parameter, we need to get new data and then save the new data as a data frame to a new object.


In [4]:
gameids.get_new_data(Season='2006-07')
gameids2006 = pd.DataFrame(gameids.game_list())
gameids2006.head()


Out[4]:
AST BLK DREB FG3A FG3M FG3_PCT FGA FGM FG_PCT FTA FTM FT_PCT GAME_DATE GAME_ID MATCHUP MIN OREB PF PLUS_MINUS PTS REB SEASON_ID STL TEAM_ABBREVIATION TEAM_ID TEAM_NAME TOV VIDEO_AVAILABLE WL
0 43 5 28 31 17 0.548 117 61 0.521 27 22 0.815 2006-12-07 0020600271 PHX @ NJN 290 11 28 4 161 39 22006 10 PHX 1610612756 Phoenix Suns 12 0 W
1 37 3 40 21 10 0.476 107 60 0.561 31 27 0.871 2006-12-07 0020600271 NJN vs. PHX 290 10 29 -4 157 50 22006 2 NJN 1610612751 New Jersey Nets 17 0 L
2 39 9 38 14 5 0.357 98 54 0.551 29 17 0.586 2007-01-24 0020600628 UTA vs. MEM 265 18 32 -2 130 56 22006 4 UTA 1610612762 Utah Jazz 14 0 L
3 26 6 37 22 8 0.364 95 54 0.568 19 15 0.789 2007-01-21 0020600604 PHX vs. MIN 240 12 21 29 131 49 22006 6 PHX 1610612756 Phoenix Suns 8 0 W
4 34 5 35 32 12 0.375 104 54 0.519 13 8 0.615 2007-01-07 0020600502 PHX vs. GSW 240 11 24 23 128 46 22006 11 PHX 1610612756 Phoenix Suns 15 0 W

A quick filter for team names that contain 'Suns' returns all games for the Suns for the 2006-07 season


In [5]:
suns_logs = gameids2006.ix[gameids2006['TEAM_NAME'].str.contains('Suns')]
suns_logs.head()


Out[5]:
AST BLK DREB FG3A FG3M FG3_PCT FGA FGM FG_PCT FTA FTM FT_PCT GAME_DATE GAME_ID MATCHUP MIN OREB PF PLUS_MINUS PTS REB SEASON_ID STL TEAM_ABBREVIATION TEAM_ID TEAM_NAME TOV VIDEO_AVAILABLE WL
0 43 5 28 31 17 0.548 117 61 0.521 27 22 0.815 2006-12-07 0020600271 PHX @ NJN 290 11 28 4 161 39 22006 10 PHX 1610612756 Phoenix Suns 12 0 W
3 26 6 37 22 8 0.364 95 54 0.568 19 15 0.789 2007-01-21 0020600604 PHX vs. MIN 240 12 21 29 131 49 22006 6 PHX 1610612756 Phoenix Suns 8 0 W
4 34 5 35 32 12 0.375 104 54 0.519 13 8 0.615 2007-01-07 0020600502 PHX vs. GSW 240 11 24 23 128 46 22006 11 PHX 1610612756 Phoenix Suns 15 0 W
10 34 7 34 43 13 0.302 105 52 0.495 28 22 0.786 2006-12-22 0020600391 PHX vs. WAS 265 12 22 -5 139 46 22006 2 PHX 1610612756 Phoenix Suns 12 0 L
18 36 2 28 34 14 0.412 90 50 0.556 28 23 0.821 2007-01-15 0020600563 PHX @ MEM 240 10 17 15 137 38 22006 9 PHX 1610612756 Phoenix Suns 13 0 W

We can verify all of the games are there by checking the shape of the data frame.


In [6]:
suns_logs.shape


Out[6]:
(82, 29)